package c.x.jy.common.utils;

import com.alibaba.fastjson.JSONObject;
@SuppressWarnings("all")
public class BaiduApiUtil {

	private static final String key = "0246eb24d325f4a651d0c4b2da90d0c1";// Gm7V8qe8l2gDYqkvoGQYEk1s2ddfhdOt
	// 30.548397,104.04701
	private static final String baduApi = "http://api.map.baidu.com/geocoder/v2/?ak=%s&location=%s&output=json&pois=1";
	private static String lotlan = "34.57234,105.73377";
	private static String lotlan1 = "34.569668,105.7222";
	


	/**
	 * "province":"四川省","city":"成都市","city_level":2,"district":"武侯区","adcode":"510107","street":"天府四街",
	 * 
	 * @param latlon
	 *            "30.548397,104.04701"
	 * @return
	 */
	public static JSONObject getBaiduAddres(String latlon) {
		if (latlon == null || !latlon.contains(","))
			return null;
		JSONObject j = (JSONObject) JSONObject.parse(HttpClientUtil.sendHttpsGet(String.format(baduApi, key, latlon)));
		//System.out.println(j.toJSONString());
		JSONObject b = ((JSONObject) ((JSONObject) j.get("result")).get("addressComponent"));
		return b;
	}

	public static void main(String[] args) {
		JSONObject j = getBaiduAddres(lotlan);
		JSONObject j1 = getBaiduAddres(lotlan1);
		System.out.println(j.get("province"));
		System.out.println(j.get("city"));
		System.out.println(j.get("district"));
		System.out.println(j.get("street"));

	}
	
	
	

}
